#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

map<string, int> m;

void init() {
    int i = 1;
    for (char a = 'a'; a <= 'z'; a++) {
        for (char b = 'a'; b <= 'z'; b++) {
            if (a == b) continue;
            else {
                string s;
                s.push_back(a);
                s.push_back(b);
                m[s] = i++;
            }
        }
    }
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    init();
    while(t--) {
        string s;
        cin >> s;
        cout << m[s] << endl;
    }
    return 0;
}